from flask import Flask
from .views import blue,admin
from .exts import init_exit
"""
初始化项目 ，创建Flask应用
"""




def create_app():
    app = Flask(__name__)
    # 注册蓝图
    app.register_blueprint(blueprint=blue)
    app.register_blueprint(blueprint=admin)

    # 配置数据库
    HOSTNAME = "localhost"  # sql主机名或IP地址
    PORT = 3306  # sql端口
    USERNAME = "root"  # 用户名
    PASSWORD = "root"  # 密码
    DATABASE = "fydb"  # 数据库名称

    app.config['SQLALCHEMY_DATABASE_URI'] = f"mysql+pymysql://{USERNAME}:{PASSWORD}@{HOSTNAME}:{PORT}/{DATABASE}?charset=utf8mb4"

    # 初始化插件
    init_exit(app=app)

    return app
